<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li {
      list-style: none;
    }

    .list li {
      line-height: 45px;
      border: 1px solid #000;
    }
  </style>
</head>

<body>
  <button id="add">新增</button>
  <button id="del">删除</button>
  <div class="list">
    <li>01</li>
    <li>02</li>
    <li>03</li>
    <li>04</li>
    <li>05</li>
    <li>06</li>
  </div>
</body>
<script>
  // HTMLCollection  元素的集合
  // document.getElementsByClassName()
  // document.getElementsByTagName()
  // 元素的集合 会随着页面查找元素的增加或减少自动更新集合

  // NodeList    节点的集合
  // document.querySelectorAll()
  // 集合一经获取 就不会再改变

  var add = document.getElementById("add");
  var del = document.getElementById("del");

  var list = document.getElementsByClassName("list")[0];
  var htmlList = list.getElementsByTagName("li");
  console.log(htmlList);

  var nodeList = document.querySelectorAll(".list li");
  console.log(nodeList);

  add.onclick = function () {
    var li = document.createElement("li");
    li.textContent = "我是新增的li";
    list.appendChild(li);

    console.log(htmlList);
    console.log(nodeList);
  }

  del.onclick = function () {
    list.lastElementChild.remove();
    console.log(htmlList);
    console.log(nodeList);
  }



</script>

</html>